<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="入库时间" prop="dateInfo" clearable>
        <el-date-picker clearable v-model="queryParams.dateInfo" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="渠道编号" prop="channelCode">
        <el-input v-model="queryParams.channelCode" placeholder="请输入渠道编号" clearable  />
      </el-form-item>

      <el-form-item label="渠道名称" prop="channelName" class="single-line-label">
        <span class="label-spacing"></span>
        <el-select v-model="queryParams.channelName" clearable placeholder="请选择渠道名称" filterable>
          <el-option v-for="(item, i) in extData.channelNameList || []" :key="i" :label="item.key"
            :value="item.key"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="客户星级" prop="starNumber">
        <el-select v-model="queryParams.starNumber" placeholder="请选择客户星级" clearable>
          <el-option v-for="(item, i) in extData.StartType || []" :key="i" :label="item.name"
            :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="stateInfo">
        <el-select v-model="queryParams.stateInfo" placeholder="请选择跟进情况" clearable>
          <el-option v-for="(item, i) in extData.DataStatus || []" :key="i" :label="item.name"
            :value="item.value"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>

    </el-form>


    <el-row :gutter="10" class="mb8">

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="poolInfoList">
      <el-table-column label="入库时间" align="center">
        <template slot-scope="scope">
          {{ formatTimestamp(scope.row.createTime) }}
        </template>
      </el-table-column>

      <el-table-column label="个人信息" align="center" width="200">
        <template slot-scope="scope">
          {{ scope.row.trealname }} -- {{ scope.row.sex === 1 ? '男' : '女' }} -- {{ scope.row.age }}
        </template>
      </el-table-column>
      <el-table-column label="所属地" align="center">
        <template slot-scope="scope">
          {{ scope.row.province }} -- {{ scope.row.city }}
        </template>
      </el-table-column>



      <el-table-column label="用户ID" align="center" prop="uid" fixed-width="200">
        <template slot-scope="scope">
          <span class="clickable-uid" @click="handleDetailsDialog(scope.row)">{{ scope.row.uid }}</span>
        </template>
      </el-table-column>


      <el-table-column label="星级" align="center" prop="starNumberName" />
      <el-table-column label="状态" align="center" prop="stateInfoName" />
      <el-table-column label="渠道名称" align="center" prop="channelName" />
      <el-table-column label="渠道编号" align="center" prop="channelCode" />

      <el-table-column label="是否分配" align="center">
        <template slot-scope="scope">
          <span :style="{ color: scope.row.status === 0 ? 'red' : 'green' }">
            {{ scope.row.status === 0 ? '未分配' : '已分配' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="分配成员" align="center" prop="nickName" />
      <el-table-column label="备注" align="center" prop="remarkInfo" width="300">
        <template slot-scope="scope">
          <span v-html="scope.row.remarkInfo"></span>
        </template>
      </el-table-column>>

    </el-table>



    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />


    <!-- 用户详情弹窗 -->
    <Member ref="MemberRef" />
  </div>
</template>

<style scoped>
.clickable-uid {
  cursor: pointer;
  color: blue;
}
</style>
<script>




import { listPoolInfo } from "@/api/merchantdata/poolInfo";
import { baseInfoData } from "@/api/merchantdata/allocateInfo";
import { baseInfoExtData } from "@/api/channel/baseInfo";
import Member from '@/views/member/memeber.vue'
export default {
  name: "PoolInfo",
  components: {
    Member
  },
  data() {
    return {
      extData: {},
      selectedRow: null,
      rules: {
        remarkInfo: [
          { required: true, message: "请输入客户跟踪", trigger: "blur" }
        ],
        starNumber: [
          { required: true, message: "请输入客户星级", trigger: "blur" }
        ]
      },
      updateType: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      userList: [],
      baseInfoList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户客户公海信息表格数据
      poolInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        dateInfo: null,
        pageNum: 1,
        pageSize: 10,
        dateInfo: null,
        starNumber: null,
        channelName: null,
        channelCode: null,
        status: null
      },
      // 表单参数
      form: {
        status: null,
        userId: null,
      },
    };
  },
  created() {
    this.getList();
    this.getOptions();

  },

  methods: {
    async getOptions() {
  try {
    const [extData1, extData2] = await Promise.all([baseInfoExtData(), baseInfoData()]);
    this.extData = { ...extData1.data, ...extData2.data };
    console.log(this.extData);
  } catch (error) {
    console.error("Error fetching data: ", error);
  }
},


    /**渠道  下拉框搜索*/
    async initData() {
      const response = await listBaseInfo()
      this.baseInfoList = response.rows;
    },

    /**用户uid跳转 */
    async handleDetailsDialog(row) {
      this.$refs.MemberRef.show(row.uid)
    },
  
    /**转换入库时间格式 */
    formatTimestamp(timestamp) {
      if (!timestamp) {
        return '';
      }
      const date = new Date(timestamp);
      const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`;
      return formattedDate;
    },



    /** 查询商户客户公海信息列表 */
    getList() {
      this.loading = true;
      listPoolInfo(this.queryParams).then(response => {
        this.poolInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.channelName = null;
      this.handleQuery();
    },






  }
};
</script>
